using System;
using System.Globalization;

namespace NWrapper.Cache
{
    /// <summary>
    /// Helper methods for cache implementations.
    /// </summary>
	public static class CacheHelper
	{
		/// <summary>
		/// Creates a cache key based on the <paramref name="key"/> object's
		/// <code>ToString()</code> and <code>GetHashCode()</code> values.
		/// </summary>
		/// <param name="key">The key of the object.</param>
		/// <returns>A formatted cache key.</returns>
		public static string GetCacheKey(object key)
		{
			if (key == null)
				throw new ArgumentNullException("key");

			if (key is string)
			{
				return (string)key;
			}
			else
			{
				return String.Concat(key.ToString(), ':', key.GetHashCode().ToString(CultureInfo.InvariantCulture));
			}
		}
	}
}
